using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Shrapnel;
using System.Runtime.Serialization;

namespace ShrapnelTest
{
	[DataContract()]
	class TestCable : Shrapnel.Cable
	{
		public TestCable(Shrapnel.Connector from, Shrapnel.Connector to)
			: base(from,to)
		{

		}


		public override void RecalculateOccupiedArea()
		{
			OccupiedArea.Clear();

			PointF start = From.OccupiedArea.TopLeftPosition + From.CableOriginOffset;
			PointF end = To.OccupiedArea.TopLeftPosition + To.CableOriginOffset;

			Shrapnel.Areas.Line lineArea = new Shrapnel.Areas.Line();
			lineArea.Start = start;
			lineArea.End = end;

			OccupiedArea.Add(lineArea);
			OccupiedArea.Update();
		}



		public override void Draw(System.Drawing.Graphics graphics, Shrapnel.ViewState viewState)
		{
			PointF start = viewState.WorldToScreen(From.OccupiedArea.TopLeftPosition + From.CableOriginOffset);
			PointF end = viewState.WorldToScreen(To.OccupiedArea.TopLeftPosition + To.CableOriginOffset);

			// A kind of nice smooth curve.

			//PointF extra1 = new PointF(
			//    start.X + (end.Y - start.Y) * 0.13f + (end.X - start.X) * 0.33f,
			//    start.Y - (end.X - start.X) * 0.13f + (end.Y - start.Y) * 0.33f);
			//PointF extra2 = new PointF(
			//    end.X + (start.Y - end.Y) * 0.13f + (start.X - end.X) * 0.33f,
			//    end.Y - (start.X - end.X) * 0.13f + (start.Y - end.Y) * 0.33f);

			using (Pen pen = new Pen(IsSelected ? Color.Yellow : Color.Black, IsSelected ? 4 : 1))
			{
				// graphics.DrawCurve(pen, new PointF[] { start, extra1, extra2, end });
				graphics.DrawLine(pen, start, end);
			}

			
		}
	}
}
